home *** CD-ROM | disk | FTP | other *** search
/ Hacker's Secrets 4 / Hacker's Secrets 4.iso / misc / cisco_c.txt < prev    next >
Text File  |  1996-06-23  |  3KB  |  168 lines

  1. /*
  2.  * Cisco password decrypter V2.0
  3.  *  (c) 1995 by SPHiXe
  4.  *
  5.  * DISCLAIMER: The author of this program takes no responsibility for
  6.  *             neither direct nor indirect damages caused by this program.
  7.  *             Misuse of this program may lead to serious problems with
  8.  *             your local authorities...
  9.  *             You should know what you're doing.
  10.  */
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <ctype.h>
  15.  
  16. char xlat[] = {
  17.     0x64, 0x73, 0x66, 0x64, 0x3b, 0x6b, 0x66, 0x6f,
  18.     0x41, 0x2c, 0x2e, 0x69, 0x79, 0x65, 0x77, 0x72,
  19.     0x6b, 0x6c, 0x64, 0x4a, 0x4b, 0x44
  20. };
  21.  
  22. char pw_str1[] = "password 7 ";
  23. char pw_str2[] = "enable-password 7 ";
  24.  
  25. char *pname;
  26.  
  27. cdecrypt(enc_pw, dec_pw)
  28. char *enc_pw;
  29. char *dec_pw;
  30. {
  31.     unsigned int seed, i, val = 0;
  32.     
  33.     if(strlen(enc_pw) & 1)
  34.         return(-1);
  35.  
  36.     seed = (enc_pw[0] - '0') * 10 + enc_pw[1] - '0';
  37.  
  38.     if (seed > 15 || !isdigit(enc_pw[0]) || !isdigit(enc_pw[1]))
  39.         return(-1);
  40.  
  41.     for (i = 2 ; i <= strlen(enc_pw); i++) {
  42.         if(i !=2 && !(i & 1)) {
  43.             dec_pw[i / 2 - 2] = val ^ xlat[seed++];
  44.             val = 0;
  45.         }
  46.         
  47.         val *= 16;
  48.     
  49.         if(isdigit(enc_pw[i] = toupper(enc_pw[i]))) {
  50.             val += enc_pw[i] - '0';
  51.             continue;
  52.         }
  53.  
  54.         if(enc_pw[i] >= 'A' && enc_pw[i] <= 'F') {
  55.             val += enc_pw[i] - 'A' + 10;
  56.             continue;
  57.         }
  58.         
  59.         if(strlen(enc_pw) != i)
  60.             return(-1);
  61.     }                       
  62.     
  63.     dec_pw[++i / 2] = 0;
  64.  
  65.     return(0);
  66. }
  67.  
  68. usage()
  69. {
  70.     fprintf(stdout, "Usage: %s -p <encrypted password>\n", pname);
  71.     fprintf(stdout, "       %s <router config file> <output file>\n", pname);
  72.  
  73.     return(0);
  74. }
  75.  
  76. main(argc,argv)
  77. int argc;
  78. char **argv;
  79.  
  80. {
  81.     FILE *in = stdin, *out = stdout;
  82.     char line[257];
  83.     char passwd[65];
  84.     unsigned int i, pw_pos;
  85.  
  86.     pname = argv[0];
  87.  
  88.     if(argc > 1)
  89.     {
  90.         if(argc > 3) {
  91.             usage();
  92.             exit(1);
  93.         }
  94.         
  95.         if(argv[1][0] == '-')
  96.         {
  97.             switch(argv[1][1]) {
  98.                 case 'h':
  99.                 usage();
  100.                 break;
  101.                 
  102.                 case 'p':
  103.                 if(cdecrypt(argv[2], passwd)) {
  104.                     fprintf(stderr, "Error.\n");
  105.                     exit(1);
  106.                 }
  107.                 fprintf(stdout, "password: %s\n", passwd);
  108.                 break;
  109.  
  110.                 default:
  111.                 fprintf(stderr, "%s: unknow option.", pname);
  112.             }
  113.             
  114.             return(0);
  115.         }
  116.  
  117.         if((in = fopen(argv[1], "rt")) == NULL)
  118.             exit(1);
  119.         if(argc > 2)
  120.             if((out = fopen(argv[2], "wt")) == NULL)
  121.                 exit(1);
  122.     }
  123.  
  124.     while(1) {
  125.         for(i = 0; i < 256; i++) {
  126.             if((line[i] = fgetc(in)) == EOF) {
  127.                 if(i)
  128.                     break;
  129.  
  130.                 fclose(in);
  131.                 fclose(out);
  132.                 return(0);
  133.             }
  134.             if(line[i] == '\r')
  135.                 i--;
  136.  
  137.             if(line[i] == '\n')
  138.                 break;
  139.         }
  140.         pw_pos = 0;
  141.         line[i] = 0;
  142.         
  143.         if(!strncmp(line, pw_str1, strlen(pw_str1)))
  144.             pw_pos = strlen(pw_str1);
  145.         
  146.         if(!strncmp(line, pw_str2, strlen(pw_str2)))
  147.             pw_pos = strlen(pw_str2);
  148.  
  149.         if(!pw_pos) {
  150.             fprintf(stdout, "%s\n", line);
  151.             continue;
  152.         }
  153.  
  154.         if(cdecrypt(&line[pw_pos], passwd)) {
  155.             fprintf(stderr, "Error.\n");
  156.             exit(1);
  157.         }
  158.         else {
  159.             if(pw_pos == strlen(pw_str1))
  160.                 fprintf(out, "%s", pw_str1);
  161.             else
  162.                 fprintf(out, "%s", pw_str2);
  163.                 
  164.             fprintf(out, "%s\n", passwd);
  165.         }
  166.     }
  167. }
  168.